import java.util.concurrent.CountDownLatch;

public class CountDown {


    /**
     * countDownLatch，主线程维护一个计数器，其他线程调用await()方法阻塞，调用countdown()计数器减1
     * 计数器为0的时候所有await()方法阻塞的线程被唤醒，并行执行
     */


    public static void main(String[] args) throws InterruptedException {

        //创建一个计数器
        CountDownLatch countDownLatch = new CountDownLatch(5);


        for (int i = 0; i < 5; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"同学出来了");
                countDownLatch.countDown();
            },String.valueOf(i)).start();
        }

        countDownLatch.await();

        System.out.println("主线程锁门");
    }
}